package cn.edu.ecut.se2024.dao;


import cn.edu.ecut.se2024.model.contracts_management.Approver;
import cn.edu.ecut.se2024.model.contracts_management.Contract;
import cn.edu.ecut.se2024.model.contracts_management.Executor;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ContractsManagementDAO {

    @Select("SELECT * FROM contract WHERE contract_id = #{id}")
    Contract findContractById(int id);

    @Insert("INSERT INTO contract (contract_number, contract_name, supplier, contract_amount, contract_status) " +
            "VALUES (#{contractNumber}, #{contractName}, #{supplier}, #{contractAmount}, #{contractStatus})")
    int insertContract(Contract contract);

    @Update("UPDATE contract SET contract_number = #{contractNumber}, contract_name = #{contractName}, " +
            "supplier = #{supplier}, contract_amount = #{contractAmount}, contract_status = #{contractStatus} " +
            "WHERE contract_id = #{contractId}")
    int updateContract(Contract contract);

    @Delete("DELETE FROM contract WHERE contract_id = #{id}")
    int deleteContract(int id);

    @Select("SELECT * FROM approver WHERE approver_id = #{id}")
    Approver findApproverById(int id);

    @Insert("INSERT INTO approver (username, password) VALUES (#{username}, #{password})")
    int insertApprover(Approver approver);

    @Update("UPDATE approver SET username = #{username}, password = #{password} WHERE approver_id = #{id}")
    int updateApprover(Approver approver);

    @Delete("DELETE FROM approver WHERE approver_id = #{id}")
    int deleteApprover(int id);

    @Select("SELECT * FROM executor WHERE executor_id = #{id}")
    Executor findExecutorById(int id);

    @Insert("INSERT INTO executor (username, password) VALUES (#{username}, #{password})")
    int insertExecutor(Executor executor);

    @Update("UPDATE executor SET username = #{username}, password = #{password} WHERE executor_id = #{id}")
    int updateExecutor(Executor executor);

    @Delete("DELETE FROM executor WHERE executor_id = #{id}")
    int deleteExecutor(int id);

    @Select("SELECT * FROM contract")
    List<Contract> getAllContracts();
}